<!DOCTYPE html>
<html lang="zh-cn">
	<head>
		<meta charset="utf-8" />
		<title>队列状态 | Houze</title>
		<meta name="viewport" content="width=device-width, initial-scale=1.0">
		<meta http-equiv="X-UA-Compatible" content="IE=edge" />
		<link href="/assets/css/bootstrap.min.css" id="bootstrap-stylesheet" rel="stylesheet" type="text/css" />
		<link href="/assets/iconfont/iconfont.css" rel="stylesheet" type="text/css" />
		<link href="/assets/css/icon.css" rel="stylesheet" type="text/css" />
		<link href="/assets/css/icons.min.css" rel="stylesheet" type="text/css" />
		<link href="/assets/libs/datatables/dataTables.bootstrap4.css" rel="stylesheet" type="text/css" />
		<link href="/assets/libs/datatables/responsive.bootstrap4.css" rel="stylesheet" type="text/css" />
		<link href="/assets/css/app.min.css" rel="stylesheet" type="text/css" />
		<link href="/assets/css/style.css" rel="stylesheet" type="text/css" />
	</head>
	<body data-sidebar="dark">
		<div id="wrapper">
			<!-- 頂部 -->
			<div class="navbar-custom">
				<ul class="list-unstyled topnav-menu float-right mb-0">
					<!-- 用戶資訊 -->
					<li class="dropdown notification-list">
						<a class="nav-link dropdown-toggle nav-user mr-0 waves-effect" data-toggle="dropdown" href="#" role="button" aria-haspopup="false" aria-expanded="false">
							<span class="pro-user-name ml-1"> 管理 <i class="mdi mdi-chevron-down"></i></span>
						</a>
						<div class="dropdown-menu dropdown-menu-right profile-dropdown ">
							<!-- item-->
							<a href="javascript:out();" class="dropdown-item notify-item">
								<i class="fe-log-out"></i>
								<span>登出</span>
							</a>
						</div>
					</li>
				</ul>
				<!-- LOGO -->
				<div class="logo-box">
					<a href="/" class="logo logo-light text-center"> 监控中心 </a>
				</div>
				<ul class="list-unstyled topnav-menu topnav-menu-left mb-0">
					<li>
						<button class="button-menu-mobile disable-btn waves-effect">
							<i class="fe-menu"></i>
						</button>
					</li>
					<li>
						<h4 class="page-title-main"> 队列状态 </h4>
					</li>
				</ul>
			</div>
			<!-- 側邊欄 -->
			<div class="left-side-menu">
				<div class="slimscroll-menu">
					<div id="sidebar-menu">
						<ul class="metismenu" id="side-menu">
							<li>
								<a href="/HttpQueue/index">
									<i class="iconfont iconhome"></i>
									<span> 队列状态 </span>
								</a>
							</li>
						</ul>
					</div>
					<div class="clearfix"></div>
				</div>
			</div>
			<div class="content-page">
				<div class="content">
					<div class="container-fluid">
						<div class="row">
							<div class="col-12">
								<div class="card-box">
									<div class="row">
										<div class="col-12">
											<div class="filter-list">
												<div class="row">
													<div class="col-md-2 col-xs-6">
														<label>自动刷新间隔（秒）</label>
														<input type="text" class="form-control" id="times" value="10">
													</div>
													<div class="col-md-2 col-xs-12">
														<label style="color: #FFF;">1</label>
														<div>
															<button class="btn btn-primary waves-effect waves-light btn-sm" id="autoReflush"> 开启 </button>
														</div>
													</div>
												</div>
											</div>
											<div style="margin-top: 20px;">
												<div class="responsive-table-plugin">
													<div class="table-rep-plugin">
														<div class="table-responsive">
															<table id="datatable" class="table table-bordered dt-responsive nowrap">
																<thead>
																	<tr>
																		<th>序号</th>
																		<th>队列名称</th>
																		<th>驱动</th>
																		<th>队列前缀</th>
																		<th>消费超时(S)</th>
																		<th>消费失败重试间隔(S)</th>
																		<th>待确认队列</th>
																		<th>等待消费队列</th>
																		<th>正在消费队列</th>
																		<th>延迟消费队列</th>
																		<th>消费失败队列</th>
																		<th>消费超时队列</th>
																		<th>Job序列化队列</th>
																		<th>操作</th>
																	</tr>
																</thead>
																<tbody>
																    {php}$i=1;{/php}
																    {foreach $list as $key=>$v}
																	<tr>
																		<td>{$i}</td>
																		<td style="color: #FF3366;">{$key}</td>
																		<td>{$v.type}</td>
																		<td>{$v.channel}</td>
																		<td>{$v.timeout}</td>
																		<td>{$v.retry_seconds|json_encode}</td>
																		<td>
																			<a style="color: #009999;" href="/HttpQueue/showlist?node={$key}&type=confirm">{$v.confirm|number_format}</a> 
																			{if ($v.confirm > 0)}
																			<button type="button" class="btn btn-primary waves-effect waves-light btn-sm" style="padding: 2px 10px;" data-toggle="modal" data-target="#clear" onclick="setVal('{$key}','confirm')">清空</button>
																			{/if}
																		</td>
																		<td>
																			<a style="color: #004D99;" href="/HttpQueue/showlist?node={$key}&type=waiting">{$v.waiting|number_format}</a>
																			{if ($v.waiting > 0)}
																			<button type="button" class="btn btn-primary waves-effect waves-light btn-sm" style="padding: 2px 10px;" data-toggle="modal" data-target="#clear" onclick="setVal('{$key}','waiting')">清空</button>
																			{/if}
																		</td>
																		<td>
																			<a style="color: #4D0099;" href="/HttpQueue/showlist?node={$key}&type=reserved">{$v.reserved|number_format}</a>
																		</td>
																		<td>
																			<a style="color: #00994D;" href="/HttpQueue/showlist?node={$key}&type=delayed">{$v.delayed|number_format}</a>
																			{if ($v.delayed > 0)}
																			<button type="button" class="btn btn-primary waves-effect waves-light btn-sm" style="padding: 2px 10px;" data-toggle="modal" data-target="#clear" onclick="setVal('{$key}','delayed')">清空</button>
																			{/if}
																		</td>
																		<td>
																			<a style="color: #4D9900;" href="/HttpQueue/showlist?node={$key}&type=failed">{$v.failed|number_format}</a>
																			{if ($v.failed > 0)}
																			<button type="button" class="btn btn-primary waves-effect waves-light btn-sm" style="padding: 2px 10px;" data-toggle="modal" data-target="#clear" onclick="setVal('{$key}','failed')">清空</button>
																			<button type="button" class="btn btn-danger waves-effect waves-light btn-sm" style="padding: 2px 10px;" data-toggle="modal" data-target="#delete" onclick="setVal('{$key}','failed')">重试</button>
																			{/if}
																		</td>
																		<td>
																			<a style="color: #990000;" href="/HttpQueue/showlist?node={$key}&type=timeout">{$v.timeout|number_format}</a>
																			{if ($v.timeout > 0)}
																			<button type="button" class="btn btn-primary waves-effect waves-light btn-sm" style="padding: 2px 10px;" data-toggle="modal" data-target="#clear" onclick="setVal('{$key}','timeout)">清空</button>
																			<button type="button" class="btn btn-danger waves-effect waves-light btn-sm" style="padding: 2px 10px;" data-toggle="modal" data-target="#delete" onclick="setVal('{$key}','timeout')">重试</button>
																			{/if}
																		</td>
																		<td>
																			<a>{$v.entity|number_format}</a>
																		</td>
																		<td>
																			<button type="button" class="btn btn-danger waves-effect waves-light btn-sm" style="padding: 2px 10px;" data-toggle="modal" data-target="#initialize" onclick="setVal('{$key}', 0)">初始化</button>
																			
																		</td>
																	</tr>
																    {php}$i++;{/php}
																	{/foreach}
																</tbody>
															</table>
														</div>
													</div>
												</div>
											</div>
										</div>
									</div>
								</div>
							</div>
						</div>
					</div>
				</div>
				<!-- 底部 -->
				<footer class="footer">
					<div class="container-fluid">
						<div class="row">
							<div class="col-md-12"> 由 <a href="" target="_blank">Houze</a> 高性能企业级PHP框架 | 提供技术支持 </div>
						</div>
					</div>
				</footer>
			</div>
		</div>
		<!-- 清空彈框 -->
		<div class="modal fade" id="clear" data-backdrop="static" tabindex="-1" role="dialog" aria-hidden="true">
			<div class="modal-dialog modal-sm" role="document">
				<div class="modal-content">
					<div class="modal-header">
						<h5 class="modal-title" id="staticBackdropLabel">提示</h5>
						<button type="button" class="close" data-dismiss="modal" aria-label="Close">
							<span aria-hidden="true">&times;</span>
						</button>
					</div>
					<div class="modal-body">
						<p class="tips-info">你确定清空该队列?</p>
					</div>
					<div class="modal-footer">
						<button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
						<button type="button" class="btn btn-primary clear">确认</button>
					</div>
				</div>
			</div>
		</div>
		<!-- 重试彈框 -->
		<div class="modal fade" id="delete" data-backdrop="static" tabindex="-1" role="dialog" aria-hidden="true">
			<div class="modal-dialog modal-sm" role="document">
				<div class="modal-content">
					<div class="modal-header">
						<h5 class="modal-title" id="staticBackdropLabel">提示</h5>
						<button type="button" class="close" data-dismiss="modal" aria-label="Close">
							<span aria-hidden="true">&times;</span>
						</button>
					</div>
					<div class="modal-body">
						<p class="tips-info">你确定将该队列全部转入等待消费队列?</p>
					</div>
					<div class="modal-footer">
						<button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
						<button type="button" class="btn btn-primary retry">确认</button>
					</div>
				</div>
			</div>
		</div>
		<!-- 初始化彈框 -->
		<div class="modal fade" id="initialize" data-backdrop="static" tabindex="-1" role="dialog" aria-hidden="true">
			<div class="modal-dialog modal-sm" role="document">
				<div class="modal-content">
					<div class="modal-header">
						<h5 class="modal-title" id="staticBackdropLabel">提示</h5>
						<button type="button" class="close" data-dismiss="modal" aria-label="Close">
							<span aria-hidden="true">&times;</span>
						</button>
					</div>
					<div class="modal-body">
						<p class="tips-info">你确定初始化该队列？<br/>该操作会将整个队列清空！</p>
					</div>
					<div class="modal-footer">
						<button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
						<button type="button" class="btn btn-primary initialize">确认</button>
					</div>
				</div>
			</div>
		</div>
		
		<input type="hidden" id="node" value=""><!--节点-->
		<input type="hidden" id="type" value=""><!--驱动-->
		<script src="/assets/js/vendor.min.js"></script>
		<script src="/assets/libs/datatables/jquery.dataTables.min.js"></script>
		<script src="/assets/libs/datatables/dataTables.bootstrap4.js"></script>
		<script src="/assets/libs/datatables/dataTables.responsive.min.js"></script>
		<!-- Datatables init -->
		<script src="/assets/js/datatables.init.js"></script>
	</body>
</html>
<script>
function setVal(node, type) {
    $('#node').val(node);
    $('#type').val(type);
}
$('.clear').click(function() {
    dialog('系统执行中，请勿刷新页面...', 'success');
    $('.close').click();
    $.ajax({
        type: 'get',
        data: {
            'node':$('#node').val(),
            'type':$('#type').val(),
        },
        url: "/HttpQueue/clears",
        success: function(data) {
            var array = eval('('+data+')');
            if (array['code'] == '00') {
                dialog(array['msg'], 'success');
                setTimeout(function() {
					window.location.reload();
				}, 800);
            } else {
                dialog(array['msg'], 'error');
            }
        }
    });
})
$('.retry').click(function() {
    dialog('系统执行中，请勿刷新页面...', 'success');
    $('.close').click();
    $.ajax({
        type: 'get',
        data: {
            'node':$('#node').val(),
            'type':$('#type').val(),
        },
        url: "/HttpQueue/retrys",
        success: function(data) {
            var array = eval('('+data+')');
            if (array['code'] == '00') {
                dialog(array['msg'], 'success');
                setTimeout(function() {
					window.location.reload();
				}, 800);
            } else {
                dialog(array['msg'], 'error');
            }
        }
    });
})
$('.initialize').click(function() {
    dialog('系统执行中，请勿刷新页面...', 'success');
    $('.close').click();
    $.ajax({
        type: 'get',
        data: {
            'node':$('#node').val(),
        },
        url: "/HttpQueue/initialize",
        success: function(data) {
            var array = eval('('+data+')');
            if (array['code'] == '00') {
                dialog(array['msg'], 'success');
                setTimeout(function() {
					window.location.reload();
				}, 800);
            } else {
                dialog(array['msg'], 'error');
            }
        }
    });
})


var fresh;
var stop = false;
$("#autoReflush").click(function(){
	var time = $('#times').val();
    if(!stop){
        //指定5秒刷新一次
        fresh = setInterval(function(){
            window.location.href='?reload=1';
        }, time * 1000); 
        $(this).text("关闭");
        stop=true;
    }else{
        clearInterval(fresh);
        $(this).text("开启");
        stop = false;
    }
});
if (getParam('reload') == 1) {
	$("#autoReflush").click();
}
function getParam(name) {
	var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
	var r = window.location.search.substr(1).match(reg);  //匹配目标参数
	if (r != null) return unescape(r[2]); return null; //返回参数值
}
function out() {
    if (confirm('你确认退出吗?')) {
        $.ajax({
            type: 'get',
            data: {
            },
            url: "/HttpQueue/out",
            success: function(data) {
                var array = eval('('+data+')');
                if (array['code'] == '00') {
                    dialog(array['msg'], 'success');
                    setTimeout(function() {
    					window.location.href = '/HttpQueue/login'
    				}, 800);
                } else {
                    dialog(array['msg'], 'error');
                }
            }
        });
    }
}
</script>